package com.example.index.widget

import android.content.Context
import androidx.appcompat.widget.AppCompatEditText
import android.util.AttributeSet
import android.util.Log
import android.view.KeyEvent
import android.widget.EditText

class CursorEditText : AppCompatEditText {
    val TAG = "CursorEditText"

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
        setOnKeyListener { v, keyCode, event ->
            //You can identify which key pressed buy checking keyCode value with KeyEvent.KEYCODE_
            Log.i(TAG, ": =============================|||||||||||")
            isDelButtonPressed = event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_DEL
            false
        }
    }

    override fun onSelectionChanged(selStart: Int, selEnd: Int) {
        super.onSelectionChanged(selStart, selEnd)
        if (selectionChangeListener != null)
            selectionChangeListener?.onSelectionChanged(selStart, selEnd)
    }

    private var isDelButtonPressed: Boolean = false

    fun isDeling() = isDelButtonPressed


    var selectionChangeListener: OnSelectionChangeListener? = null

    interface OnSelectionChangeListener {
        fun onSelectionChanged(selStart: Int, selEnd: Int)
    }
}